package epam.car.rent;

import java.io.FileNotFoundException;
import java.util.ArrayList;

import dataAccess.DbWriter;
//import epam.car.rent.dialogs.*;
import epam.car.rent.exceptions.CarException;

public class CarRentLoader {

	public static void main(String[] args) {
		
//		try {
//			Management.importCarsFromFile("testfiles\\clients.xml", WriterType.XML);

//  xml import is not implemented for entities CARS and ORDERS, but the
//	implementation is quite similar.
//			
//			Management.importCarsFromFile("testfiles\\cars.xml", WriterType.xml);
//			Management.importOrdersFromFile("testfiles\\orders.xml", WriterType.xml);
			
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IllegalArgumentException e) {
//			e.printStackTrace();
//		} catch (CarException e) {
//			e.printStackTrace();
//		}
//		Management.printCars();
//		Management.printCars();
//		Management.printOrders();
//		
//		System.out.println("xml data loaded.");
//		
//		System.out.println("Storing this data to database.");
//		
//		DbWriter.storeAllToDb();
//		
//		System.out.println("Data is stored to db.");
		
//		Management.exportCarsToFile("E:\\carrentexports\\bigbase\\clients.xml", WriterType.xml);
//		Management.exportCarsToFile("E:\\carrentexports\\bigbase\\cars.xml", WriterType.xml);
//		Management.exportOrdersToFile("E:\\carrentexports\\bigbase\\orders.xml", WriterType.xml);
		

///////////		
/////////// creating objects, adding them into database and then updating them
///////////		

//		System.out.println("Creating objects and storing them to db.");
//		Car c1 = (Car) Management.create("Anton Qupsedov", "XX911126", 4000.5F, "tratata", "tmp@usa.com");
//		DbWriter.addToDb(c1);
//		c1.setEmail("anton@gmail.com");
//		DbWriter.update(c1);
		
//		long carId = DbWriter.addToDb(Management.create("Hummer", 222000, "LUXURY"));
//		Management.getCarById(carId).setDamages(Damages.HARD);
//		DbWriter.update(Management.getCarById(carId));
//		
//		carId = DbWriter.addToDb(Management.create("Kia", 52100, "ECONOMY"));
//		Management.getCarById(carId).setDamages(Damages.NONE);
//		DbWriter.update(Management.getCarById(carId));
//		
//		carId = DbWriter.addToDb(Management.create("KAMAZ", 90000, "FULLSIZE"));
//		Management.getCarById(carId).setDamages(Damages.NONE);
//		DbWriter.update(Management.getCarById(carId));
//		
//		carId = DbWriter.addToDb(Management.create("Volga", 15000, "MIDSIZE"));
//		Management.getCarById(carId).setDamages(Damages.NONE);
//		DbWriter.update(Management.getCarById(carId));
		
//		
//		DbWriter.addToDb(Management.create("Dima", "dimapwd"));
//		
//		Order o = Management.rentCar(Management.getManagerByName("Dima"), 
//				Management.getCarById(carId), 
//				Management.getCarByPID("XX911126"), 
//				"2010-11-19");
//		DbWriter.addToDb(o);
//		
//		o.rejectOrder("Not allowed at this time, sorry.");
//		DbWriter.update(o);
//		
//		DbWriter.requestAllFromDb();

	////// DELETING RECORDS ///
		
//		System.out.println("Deleting data from db.");
		
//		DbWriter.delete(Management.getOrderById(o.getId()));
//		DbWriter.delete(Management.getCarById(carId));
//		DbWriter.delete(Management.getManagerByName("Dima"));
//		DbWriter.delete(Management.getCarByPID("XX911126"));

//		DbWriter.requestAllFromDb();
		
////////		
////////		
////////
		
		 
		 
		 

/////// old dialog system, not updated for new commands yet
		 
//		Dialogs.helloDialog();
//		
//		DbWriter.requestAllFromDb();
//		Management.printCars();
//		
//		System.out.println(DbWriter.getClientById("TA111111").getName());
		
		ArrayList<Order> orders = new ArrayList<Order>();
		
		orders = DbWriter.getOrdersForClient("TA111111");
		
		for (Order o : orders){
			System.out.println(o.toString());
		}
		
	}
}
